package chan.com.huishang.http;

import java.io.File;

import chan.com.huishang.application.Allplication;
import chan.com.huishang.http.callback.NetServer;
import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;

/**
 * Created by chen on 2017/12/27.
 */
public class HttpManager {

    private Retrofit mRetrofit;

    private OkHttpClient mHttpClient;


    private NetServer mNetServer;

    public HttpManager(String url, Interceptor interceptor, Interceptor netIntercepter) {
        OkHttpClient.Builder builder = new OkHttpClient().newBuilder();
        builder.cache(new Cache(new File(Allplication.getInstance().getCacheDir(), "catsches"), 1024 * 1024 * 100));
        mHttpClient = builder.addInterceptor(interceptor).addNetworkInterceptor(netIntercepter).retryOnConnectionFailure(true).build();
        mRetrofit = new Retrofit.Builder().baseUrl(url).client(mHttpClient).build();
        mNetServer = mRetrofit.create(NetServer.class);
    }

    public NetServer getmNetServer() {
        return mNetServer;
    }
}
